<div class="row-fluid">
    <div class="span12">
        <div class="box box-bordered box-color">
            <div class="box-content">
                <?php /*echo (empty($new) && $new != 1)? $this->Form->input('id') : '';*/?>
                <div class="span12 nomargin">
                    <div class="control-group">
                        <div class="controls-row">
                            <div class="controls span12">
                                <label for="nameAnime"><strong>Nome do Anime:</strong>&nbsp;</label>
                                <strong id="nameAnime" class="label label-green">Anime</strong>
                            </div>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls-row">
                            <div class="controls span6">
                                <?php echo $this->Form->input('situation_id',array('label'=>array('text'=>'Situação','class'=>'font-strong'),'class'=>'span12 chosen-select',"data-placeholder"=>"Defina uma Situação",'div'=>false,'empty'=>true)); ?>
                            </div>
                            <div class="controls span6">
                                <?php echo $this->Form->input('rating_id',array('label'=>array('text'=>'Avaliação','class'=>'font-strong'),'class'=>'span12 chosen-select',"data-placeholder"=>"Faça uma Avaliação",'div'=>false,'empty'=>true)); ?>
                            </div>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls-row">
                            <div class="controls span4 nomargin">
                                <?php echo $this->Form->input('name',array('label'=>array('text'=>'Temporada / Arco','class'=>'font-strong'),'class'=>'span12','placeholder'=>'Primeira','div'=>false)); ?>
                            </div>
                            <div class="controls span4">
                                <label class="font-strong">Ano de Lançamento</label>
                                <?php echo $this->Form->year('release_year',1990,date('Y'),array('class'=>'span12 datepick nomarginbottom','div'=>false)); ?>
                            </div>
                            <div class="controls span4">
                                <?php echo $this->Form->input('release_date',array('type'=>'text','label'=>'Data de Lançamento','class'=>'span12 datepick nomarginbottom','data-date-format'=>"dd/mm/yyyy",'div'=>false)); ?>
                            </div>
                        </div>
                    </div>
                    <div class="control-group">
                        <div class="controls-row">
                            <div class="controls span3 nomargin">
                                <?php
                                echo $this->Form->label('dow_episodes','Episodios Assistidos',array('class'=>'font-strong'));
                                echo $this->Form->number('dow_episodes',array('class'=>'span12','min'=>'0','value'=>'0','div'=>false)); ?>
                            </div>
                            <div class="controls span3">
                                <?php
                                echo $this->Form->label('full_episodes','Total de Episodios',array('class'=>'font-strong'));
                                echo $this->Form->number('full_episodes',array('class'=>'span12','min'=>'0','value'=>'12','div'=>false)); ?>
                            </div>
                            <div class="controls span3">
                                <?php
                                echo $this->Form->label('start_season','Inicio da Temporada',array('class'=>'font-strong'));
                                echo $this->Form->number('start_season',array('class'=>'span12','min'=>'1','value'=>'1','div'=>false)); ?>
                            </div>
                            <div class="controls span3">
                                <?php
                                echo $this->Form->label('end_season','Fim da Temporada',array('class'=>'font-strong'));
                                echo $this->Form->number('end_season',array('class'=>'span12','min'=>'12','value'=>'12','div'=>false)); ?>
                            </div>
                        </div>
                    </div>
                    <div class="control-group">
                        <?php echo $this->Form->button('<i class=" icon-ok"></i> Concluir',array('type'=>'button','id'=>'addSeason','class'=>'btn btn-primary','div'=>'false','escape'=>false)); ?>
                        <?php echo $this->Html->link('<i class="icon-reply"></i> Cancelar','javascrip:void(0);',array('escape'=>false,'class'=>'btn btn-danger ','data-dismiss'=>'modal'))?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        var nome = document.getElementById('AnimeName').value;
        $("#nameAnime").text('');
        $("#nameAnime").text(nome);
        var i = 1;
        $('#addSeason').click(function(){

            var seasonListaId = $('#listaSeason').attr('data-value');
            var nameSeason = document.getElementById('name').value;
            var situationSeason = document.getElementById('situation_id').value;
            var situationSeason_text = document.getElementById('situation_id');
            var situationSeason_text = situationSeason_text.options[situationSeason_text.selectedIndex].text;
            var ratingSeason = document.getElementById('rating_id').value;
            var ratingSeason_text = document.getElementById('rating_id');
            var ratingSeason_text = ratingSeason_text.options[ratingSeason_text.selectedIndex].text;
            var yearSeason = document.getElementById('release_yearYear').value;
            var dateSeason = document.getElementById('release_date').value;
            var dowSeason = document.getElementById('dow_episodes').value;
            var fullSeason = document.getElementById('full_episodes').value;
            var starSeason = document.getElementById('start_season').value;
            var endSeason = document.getElementById('end_season').value;

            var btnRemove = '<a href="javascript:;" onclick="$(this).parent().parent().remove();" class="btn btn-mini btn-darkblue pull-right"><i class="icon-remove"></i></a>';

            $('#listaSeason').attr('data-value',i);
            var j = i;
            if(seasonListaId > i || seasonListaId == i)
            {
                j = parseInt(seasonListaId);
                j = j+1;
                $('#listaSeason').attr('data-value','');
                $('#listaSeason').attr('data-value',j);
            }

            var texto = '' +
                '<tr id="season'+j+'">' +
                '<input type="hidden" size="1" name="data[Season]['+j+'][name]" value="'+nameSeason+'"/>' +
                '<input type="hidden" size="1" name="data[Season]['+j+'][situation_id]" value="'+situationSeason+'"/>' +
                '<input type="hidden" size="1" name="data[Season]['+j+'][rating_id]" value="'+ratingSeason+'"/>' +
                '<input type="hidden" size="1" name="data[Season]['+j+'][release_year]" value="'+yearSeason+'"/>' +
                '<input type="hidden" size="1" name="data[Season]['+j+'][release_date]" value="'+dateSeason+'"/>' +
                '<input type="hidden" size="1" name="data[Season]['+j+'][dow_episodes]" value="'+dowSeason+'"/>' +
                '<input type="hidden" size="1" name="data[Season]['+j+'][full_episodes]" value="'+fullSeason+'"/>' +
                '<input type="hidden" size="1" name="data[Season]['+j+'][start_season]" value="'+starSeason+'"/>' +
                '<input type="hidden" size="1" name="data[Season]['+j+'][end_season]" value="'+endSeason+'"/>' +
                '<span class="span11 nomargin">' +
                '<td><strong>'+nameSeason+'</strong></td><td>'+situationSeason_text+'</td><td>'+ratingSeason_text+'</td><td>'+yearSeason+'</td><td>'+dowSeason+'&nbsp;de&nbsp;'+fullSeason+'</td><td>'+starSeason+'&nbsp; e &nbsp;'+endSeason+
                '</td>' +
                '<td>'+btnRemove+'</td>' +
                '</tr>';
            $("#boxSeason").show();
            $(texto).appendTo('#listaSeason');
            i++;
        });
    });
</script>
